package com.example.demo.test.alc.login;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class AccountLoginContext {
    @Autowired
    public Map<String, AccountLoginStrategy> loginStrategyMap = new ConcurrentHashMap<>(3);

    public AccountLoginStrategy getStrategy(String component) {
        AccountLoginStrategy strategy = loginStrategyMap.get(component);
        if(strategy == null) {
            throw new RuntimeException("no strategy defined");
        }
        return strategy;
    }

    public String test() {
        return "动态执行方法成功";
    }
}
